VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form frmEliminazioni 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Eliminazioni"
   ClientHeight    =   5160
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   12585
   Icon            =   "frmEliminazioni.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5160
   ScaleWidth      =   12585
   Begin VB.Frame Frame2 
      Height          =   4215
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   12375
      Begin MSFlexGridLib.MSFlexGrid flxGriglia 
         Height          =   3855
         Left            =   120
         TabIndex        =   1
         Top             =   240
         Width           =   12135
         _ExtentX        =   21405
         _ExtentY        =   6800
         _Version        =   393216
         Cols            =   12
         FixedCols       =   0
         FormatString    =   $"frmEliminazioni.frx":058A
      End
      Begin VB.Label lblFiltro 
         BackColor       =   &H00FFFFFF&
         Height          =   255
         Left            =   0
         TabIndex        =   2
         Top             =   0
         Visible         =   0   'False
         Width           =   375
      End
   End
   Begin VB.Frame Frame3 
      Height          =   855
      Left            =   120
      TabIndex        =   3
      Top             =   4200
      Width           =   12375
      Begin VB.CommandButton cmdStampa 
         Caption         =   "&Stampa "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   9480
         TabIndex        =   5
         Top             =   240
         Width           =   1335
      End
      Begin VB.CommandButton cmdChiudi 
         Caption         =   "&Chiudi"
         CausesValidation=   0   'False
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   11040
         TabIndex        =   4
         Top             =   240
         Width           =   1215
      End
   End
End
Attribute VB_Name = "frmEliminazioni"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Const formatStrum As String = " | Nome                  | Cognome                | Tipo                  | Data            | Ora         | Nome Paz.          | Cognome Paz.        | Data esame   | Organo               | Esame             "
Const formatLab As String = " | Nome                  | Cognome                | Tipo                  | Data            | Ora         | Nome Paz.          | Cognome Paz.        | Data esame   | Esame              "
Const formatTerapiaDialitica As String = " | Nome                  | Cognome                | Tipo                  | Data            | Ora         | Nome Paz.          | Cognome Paz.        | Data terapia   |Medicinale               | Posologia | Somministrazione | Note                | Lun | Mar | Mer | Gio | Ven | Sab | Dom | Tutti | Sospesa | Data sosp. | CAS"
Const formatTerapiaDomiciliare As String = " | Nome                  | Cognome                | Tipo                  | Data            | Ora         | Nome Paz.          | Cognome Paz.        | Data terapia   |Medicinale               | Posologia | Somministrazione        | Lun | Mar | Mer | Gio | Ven | Sab | Dom | Tutti | Sospesa | Data sosp. "
Const formatUtenti As String = " | Nome                  | Cognome                | Tipo                  | Data            | Ora         |Nome eliminato        | Cognome eliminato          | Tipo eliminato       "

Dim tFiltro As structFiltro
Const ICS As String = "  X"

Private Sub Form_Activate()
    Dim tempo As Single
    tempo = Timer
    Do
        DoEvents
    Loop Until tempo + 0.1 < Timer
    Me.ZOrder
    numFormAttivo = Me.Tag
    Call RicaricaFiltro(tFiltro)
End Sub

Private Sub Form_Load()
    Dim i As Integer
    Me.Top = 0
    Me.Left = 10
    Select Case tEliminazione
        Case tpSTRUMETALI
            Me.Caption = "Eliminazioni Esami Strumentali"
        Case tpLAB
            Me.Caption = "Eliminazioni Esami di Laboratorio"
        Case tpTERAPIEDIALITICHE
            Me.Caption = "Eliminazioni Terapie Dialitiche"
        Case tpTERAPIEDOMICILIARI
            Me.Caption = "Eliminazioni Terapie Domiciliari"
        Case tpUTENTI
            Me.Caption = "Eliminazioni Utenti"
    End Select
    With flxGriglia
        .Cols = 2
        .FormatString = Choose(tEliminazione, formatStrum, formatLab, formatTerapiaDialitica, formatTerapiaDomiciliare, formatUtenti)
        .ColWidth(0) = 0
        .Row = 0
        For i = 1 To .Cols - 1
            .Col = i
            .CellFontBold = True
        Next i
    End With
    Call CaricaFlx
    numFormAperti = numFormAperti + 1
    Me.Tag = numFormAperti
    If numFormAperti = 1 Then
        frmMain.Height = 10500
        frmMain.picSfondo.Height = 2175
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    numFormAperti = numFormAperti - 1
    If numFormAperti = 0 Then
        frmMain.Height = 9330
        frmMain.picSfondo.Height = 15
    End If
End Sub

Private Sub StampaTerapieDomiciliari()
    Dim rsDataset As Recordset
    Dim SQLString As String
    Dim cnConn As Connection        ' connessione per lo shape
    Dim rsMain As Recordset         ' recordset padre per lo shape
    
    Dim dataDal As Date
    Dim dataAl As Date
    Dim strData As String
    Dim strUtente As String
    
    SQLString = "SHAPE APPEND " & _
                "       NEW adVarChar(20) AS NOME, " & _
                "       NEW adVarChar(20) AS COGNOME, " & _
                "       NEW adVarChar(20)  AS TIPO, " & _
                "       NEW adVarChar(15) AS DATA, " & _
                "       NEW adVarChar(10) AS ORA, " & _
                "       NEW adVarChar(20)  AS NOME_PAZIENTE, " & _
                "       NEW adVarChar(20) AS COGNOME_PAZIENTE, " & _
                "       NEW adVarChar(15) AS DATA_TERAPIA, " & _
                "       NEW adVarChar(25) AS MEDICINALE, " & _
                "       NEW adLongVarChar AS POSOLOGIA, " & _
                "       NEW adVarChar(25) AS SOMMINISTRAZIONE "

                
    ' apre la connessione per lo shape
    Set cnConn = New ADODB.Connection
    cnConn.Open "Data Provider=NONE; Provider=MSDataShape"
    Set rsMain = New ADODB.Recordset
    rsMain.Open SQLString, cnConn, adOpenStatic, adLockOptimistic
                   
    If tStampe.utente <> tpTUTTI Then
        strUtente = " AND TIPO=" & tStampe.utente
    End If
    
    If Not tStampe.tutteLeDate Then
        dataDal = DateValue(Month(tStampe.dataDal) & "/" & Day(tStampe.dataDal) & "/" & Year(tStampe.dataDal))
        dataAl = DateValue(Month(tStampe.dataAl) & "/" & Day(tStampe.dataAl) & "/" & Year(tStampe.dataAl))
        strData = " AND (DATA BETWEEN #" & dataDal & "# AND #" & dataAl & "#) "
    End If
    
    Set rsDataset = New Recordset
    rsDataset.Open "SELECT * FROM (LOGIN U1 INNER JOIN E_TERAPIE_DOMICILIARI E ON U1.KEY=E.CODICE_UTENTE) INNER JOIN PAZIENTI P ON P.KEY=E.CODICE_PAZIENTE WHERE TRUE " & strData & strUtente & " ORDER BY DATA DESC", cnPrinc, adOpenForwardOnly, adLockReadOnly, adCmdText
    If Not (rsDataset.EOF And rsDataset.BOF) Then
        With rsMain
            Do While Not rsDataset.EOF
                .AddNew
                .Fields("NOME") = rsDataset("U1.NOME")
                .Fields("COGNOME") = rsDataset("U1.COGNOME")
                .Fields("TIPO") = Choose(rsDataset(IIf(tEliminazione = tpUTENTI, "U1.", "") & "TIPO"), "Medico", "Infermiere", "Contabile", "Amministratore")
                .Fields("DATA") = rsDataset("DATA")
                .Fields("ORA") = Format(rsDataset("ORA"), "Short Time")
                .Fields("NOME_PAZIENTE") = rsDataset("P.NOME")
                .Fields("COGNOME_PAZIENTE") = rsDataset("P.COGNOME")
                .Fields("DATA_TERAPIA") = rsDataset("DATA_TERAPIA")
                .Fields("MEDICINALE") = GetNome(rsDataset("CODICE_MEDICINALE"), "MEDICINALI")
                .Fields("POSOLOGIA") = rsDataset("POSOLOGIA")
                .Fields("SOMMINISTRAZIONE") = IIf(rsDataset("SOMMINISTRAZIONE") = 1, "Intradialitica", "Postdialitica")
                rsDataset.MoveNext
            Loop
        End With
    End If
    rsDataset.Close
    Set rsDataset = Nothing
        
    Set rptTerapieDomiciliariEliminazione.DataSource = rsMain
    rptTerapieDomiciliariEliminazione.Orientation = rptOrientLandscape
    rptTerapieDomiciliariEliminazione.PrintReport True, rptRangeAllPages
End Sub

Private Sub StampaTerapieDialitiche()
    Dim rsDataset As Recordset
    Dim SQLString As String
    Dim cnConn As Connection        ' connessione per lo shape
    Dim rsMain As Recordset         ' recordset padre per lo shape
    
    Dim dataDal As Date
    Dim dataAl As Date
    Dim strData As String
    Dim strUtente As String
    
    SQLString = "SHAPE APPEND " & _
                "       NEW adVarChar(20) AS NOME, " & _
                "       NEW adVarChar(20) AS COGNOME, " & _
                "       NEW adVarChar(20)  AS TIPO, " & _
                "       NEW adVarChar(15) AS DATA, " & _
                "       NEW adVarChar(10) AS ORA, " & _
                "       NEW adVarChar(20)  AS NOME_PAZIENTE, " & _
                "       NEW adVarChar(20) AS COGNOME_PAZIENTE, " & _
                "       NEW adVarChar(15) AS DATA_TERAPIA, " & _
                "       NEW adVarChar(25) AS MEDICINALE, " & _
                "       NEW adLongVarChar AS POSOLOGIA, " & _
                "       NEW adVarChar(25) AS SOMMINISTRAZIONE, " & _
                "       NEW adLongVarChar AS NOTE "

                
    ' apre la connessione per lo shape
    Set cnConn = New ADODB.Connection
    cnConn.Open "Data Provider=NONE; Provider=MSDataShape"
    Set rsMain = New ADODB.Recordset
    rsMain.Open SQLString, cnConn, adOpenStatic, adLockOptimistic
                   
    If tStampe.utente <> tpTUTTI Then
        strUtente = " AND TIPO=" & tStampe.utente
    End If
    
    If Not tStampe.tutteLeDate Then
        dataDal = DateValue(Month(tStampe.dataDal) & "/" & Day(tStampe.dataDal) & "/" & Year(tStampe.dataDal))
        dataAl = DateValue(Month(tStampe.dataAl) & "/" & Day(tStampe.dataAl) & "/" & Year(tStampe.dataAl))
        strData = " AND (DATA BETWEEN #" & dataDal & "# AND #" & dataAl & "#) "
    End If
    
    Set rsDataset = New Recordset
    rsDataset.Open "SELECT * FROM (LOGIN U1 INNER JOIN E_TERAPIE_DIALITICHE E ON U1.KEY=E.CODICE_UTENTE) INNER JOIN PAZIENTI P ON P.KEY=E.CODICE_PAZIENTE WHERE TRUE " & strData & strUtente & " ORDER BY DATA DESC", cnPrinc, adOpenForwardOnly, adLockReadOnly, adCmdText
    If Not (rsDataset.EOF And rsDataset.BOF) Then
        With rsMain
            Do While Not rsDataset.EOF
                .AddNew
                .Fields("NOME") = rsDataset("U1.NOME")
                .Fields("COGNOME") = rsDataset("U1.COGNOME")
                .Fields("TIPO") = Choose(rsDataset(IIf(tEliminazione = tpUTENTI, "U1.", "") & "TIPO"), "Medico", "Infermiere", "Contabile", "Amministratore")
                .Fields("DATA") = rsDataset("DATA")
                .Fields("ORA") = Format(rsDataset("ORA"), "Short Time")
                .Fields("NOME_PAZIENTE") = rsDataset("P.NOME")
                .Fields("COGNOME_PAZIENTE") = rsDataset("P.COGNOME")
                .Fields("DATA_TERAPIA") = rsDataset("DATA_TERAPIA")
                .Fields("MEDICINALE") = GetNome(rsDataset("CODICE_MEDICINALE"), "MEDICINALI")
                .Fields("POSOLOGIA") = rsDataset("POSOLOGIA")
                .Fields("SOMMINISTRAZIONE") = IIf(rsDataset("SOMMINISTRAZIONE") = 1, "Intradialitica", "Postdialitica")
                .Fields("NOTE") = rsDataset("NOTE")
                rsDataset.MoveNext
            Loop
        End With
    End If
    rsDataset.Close
    Set rsDataset = Nothing
        
    Set rptTerapieDialiticheEliminazione.DataSource = rsMain
    rptTerapieDialiticheEliminazione.Orientation = rptOrientLandscape
    rptTerapieDialiticheEliminazione.PrintReport True, rptRangeAllPages
End Sub

Private Sub StampeUtentiEliminazione()
    Dim rsDataset As Recordset
    Dim SQLString As String
    Dim cnConn As Connection        ' connessione per lo shape
    Dim rsMain As Recordset         ' recordset padre per lo shape

    Dim dataDal As Date
    Dim dataAl As Date
    Dim strData As String
    Dim strUtente As String
    
    SQLString = "SHAPE APPEND " & _
                "       NEW adVarChar(20) AS NOME, " & _
                "       NEW adVarChar(20) AS COGNOME, " & _
                "       NEW adVarChar(20)  AS TIPO, " & _
                "       NEW adVarChar(15) AS DATA, " & _
                "       NEW adVarChar(10) AS ORA, " & _
                "       NEW adVarChar(20)  AS NOME_ELIMINATO, " & _
                "       NEW adVarChar(20) AS COGNOME_ELIMINATO, " & _
                "       NEW adVarChar(20) AS TIPO_ELIMINATO "

                
    ' apre la connessione per lo shape
    Set cnConn = New ADODB.Connection
    cnConn.Open "Data Provider=NONE; Provider=MSDataShape"
    Set rsMain = New ADODB.Recordset
    rsMain.Open SQLString, cnConn, adOpenStatic, adLockOptimistic
                   
    If tStampe.utente <> tpTUTTI Then
        strUtente = " AND TIPO=" & tStampe.utente
    End If
    
    If Not tStampe.tutteLeDate Then
        dataDal = DateValue(Month(tStampe.dataDal) & "/" & Day(tStampe.dataDal) & "/" & Year(tStampe.dataDal))
        dataAl = DateValue(Month(tStampe.dataAl) & "/" & Day(tStampe.dataAl) & "/" & Year(tStampe.dataAl))
        strData = " AND (DATA BETWEEN #" & dataDal & "# AND #" & dataAl & "#) "
    End If
    
    Set rsDataset = New Recordset
    rsDataset.Open "SELECT * FROM (LOGIN U1 INNER JOIN E_UTENTI E ON U1.KEY=E.CODICE_UTENTE) INNER JOIN LOGIN U2 ON U2.KEY=E.CODICE_ELIMINATO WHERE TRUE " & strData & strUtente & " ORDER BY DATA DESC", cnPrinc, adOpenForwardOnly, adLockReadOnly, adCmdText
    If Not (rsDataset.EOF And rsDataset.BOF) Then
        With rsMain
            Do While Not rsDataset.EOF
                .AddNew
                .Fields("NOME") = rsDataset("U1.NOME")
                .Fields("COGNOME") = rsDataset("U1.COGNOME")
                .Fields("TIPO") = Choose(rsDataset(IIf(tEliminazione = tpUTENTI, "U1.", "") & "TIPO"), "Medico", "Infermiere", "Contabile", "Amministratore")
                .Fields("DATA") = rsDataset("DATA")
                .Fields("ORA") = Format(rsDataset("ORA"), "Short Time")
                .Fields("NOME_ELIMINATO") = rsDataset("U2.NOME")
                .Fields("COGNOME_ELIMINATO") = rsDataset("U2.COGNOME")
                .Fields("TIPO_ELIMINATO") = Choose(rsDataset("U2.TIPO"), "Medico", "Infermiere", "Contabile", "Amministratore")
                rsDataset.MoveNext
            Loop
        End With
    End If
    rsDataset.Close
    Set rsDataset = Nothing
        
    Set rptUtentiEliminazione.DataSource = rsMain
    rptUtentiEliminazione.RightMargin = 0
    rptUtentiEliminazione.LeftMargin = 0
    rptUtentiEliminazione.PrintReport True, rptRangeAllPages
End Sub

Private Sub StampaEsamiLabEliminazione()
    Dim rsDataset As Recordset
    Dim SQLString As String
    Dim cnConn As Connection        ' connessione per lo shape
    Dim rsMain As Recordset         ' recordset padre per lo shape
    
    Dim dataDal As Date
    Dim dataAl As Date
    Dim strData As String
    Dim strUtente As String
    
    SQLString = "SHAPE APPEND " & _
                "       NEW adVarChar(20) AS NOME, " & _
                "       NEW adVarChar(20) AS COGNOME, " & _
                "       NEW adVarChar(20)  AS TIPO, " & _
                "       NEW adVarChar(15) AS DATA, " & _
                "       NEW adVarChar(10) AS ORA, " & _
                "       NEW adVarChar(20)  AS NOME_PAZIENTE, " & _
                "       NEW adVarChar(20) AS COGNOME_PAZIENTE, " & _
                "       NEW adVarChar(15) AS DATA_ESAME, " & _
                "       NEW adVarChar(50)  AS ESAME "

                
    ' apre la connessione per lo shape
    Set cnConn = New ADODB.Connection
    cnConn.Open "Data Provider=NONE; Provider=MSDataShape"
    Set rsMain = New ADODB.Recordset
    rsMain.Open SQLString, cnConn, adOpenStatic, adLockOptimistic
                   
    If tStampe.utente <> tpTUTTI Then
        strUtente = " AND TIPO=" & tStampe.utente
    End If
    
    If Not tStampe.tutteLeDate Then
        dataDal = DateValue(Month(tStampe.dataDal) & "/" & Day(tStampe.dataDal) & "/" & Year(tStampe.dataDal))
        dataAl = DateValue(Month(tStampe.dataAl) & "/" & Day(tStampe.dataAl) & "/" & Year(tStampe.dataAl))
        strData = " AND (DATA BETWEEN #" & dataDal & "# AND #" & dataAl & "#) "
    End If
    
    Set rsDataset = New Recordset
    rsDataset.Open "SELECT * FROM ((LOGIN U1 INNER JOIN E_ESAMI_LAB E ON U1.KEY=E.CODICE_UTENTE)INNER JOIN PAZIENTI P ON P.KEY=E.CODICE_PAZIENTE) INNER JOIN INFO_ESAMI_LAB I ON E.KEY=I.CODICE_ELIMINAZIONE WHERE TRUE " & strData & strUtente & " ORDER BY DATA DESC", cnPrinc, adOpenForwardOnly, adLockReadOnly, adCmdText
    If Not (rsDataset.EOF And rsDataset.BOF) Then
        With rsMain
            Do While Not rsDataset.EOF
                .AddNew
                .Fields("NOME") = rsDataset("U1.NOME")
                .Fields("COGNOME") = rsDataset("U1.COGNOME")
                .Fields("TIPO") = Choose(rsDataset(IIf(tEliminazione = tpUTENTI, "U1.", "") & "TIPO"), "Medico", "Infermiere", "Contabile", "Amministratore")
                .Fields("DATA") = rsDataset("DATA")
                .Fields("ORA") = Format(rsDataset("ORA"), "Short Time")
                .Fields("NOME_PAZIENTE") = rsDataset("P.NOME")
                .Fields("COGNOME_PAZIENTE") = rsDataset("P.COGNOME")
                .Fields("DATA_ESAME") = rsDataset("DATA_ESAME")
                .Fields("ESAME") = GetNome(rsDataset("CODICE_ESAME"), "GRUPPI_ESAMI")
                rsDataset.MoveNext
            Loop
        End With
    End If
    rsDataset.Close
    Set rsDataset = Nothing
        
    Set rptEsamiLabEliminazione.DataSource = rsMain
    rptEsamiLabEliminazione.Orientation = rptOrientLandscape
    rptEsamiLabEliminazione.PrintReport True, rptRangeAllPages
End Sub

Private Sub StampaEsamiStrumentaliEliminazione()
    Dim rsDataset As Recordset
    Dim SQLString As String
    Dim cnConn As Connection        ' connessione per lo shape
    Dim rsMain As Recordset         ' recordset padre per lo shape
    
    Dim dataDal As Date
    Dim dataAl As Date
    Dim strData As String
    Dim strUtente As String
    
    SQLString = "SHAPE APPEND " & _
                "       NEW adVarChar(20) AS NOME, " & _
                "       NEW adVarChar(20) AS COGNOME, " & _
                "       NEW adVarChar(20)  AS TIPO, " & _
                "       NEW adVarChar(15) AS DATA, " & _
                "       NEW adVarChar(10) AS ORA, " & _
                "       NEW adVarChar(20)  AS NOME_PAZIENTE, " & _
                "       NEW adVarChar(20) AS COGNOME_PAZIENTE, " & _
                "       NEW adVarChar(15) AS DATA_ESAME, " & _
                "       NEW adVarChar(50) AS ORGANO, " & _
                "       NEW adVarChar(50)  AS ESAME "

                
    ' apre la connessione per lo shape
    Set cnConn = New ADODB.Connection
    cnConn.Open "Data Provider=NONE; Provider=MSDataShape"
    Set rsMain = New ADODB.Recordset
    rsMain.Open SQLString, cnConn, adOpenStatic, adLockOptimistic
                   
    If tStampe.utente <> tpTUTTI Then
        strUtente = " AND TIPO=" & tStampe.utente
    End If
    
    If Not tStampe.tutteLeDate Then
        dataDal = DateValue(Month(tStampe.dataDal) & "/" & Day(tStampe.dataDal) & "/" & Year(tStampe.dataDal))
        dataAl = DateValue(Month(tStampe.dataAl) & "/" & Day(tStampe.dataAl) & "/" & Year(tStampe.dataAl))
        strData = " AND (DATA BETWEEN #" & dataDal & "# AND #" & dataAl & "#) "
    End If
    
    Set rsDataset = New Recordset
    rsDataset.Open "SELECT * FROM (LOGIN U1 INNER JOIN E_ESAMI_STRUMENTALI E ON U1.KEY=E.CODICE_UTENTE) INNER JOIN PAZIENTI P ON P.KEY=E.CODICE_PAZIENTE WHERE TRUE " & strData & strUtente & " ORDER BY DATA DESC", cnPrinc, adOpenForwardOnly, adLockReadOnly, adCmdText
    If Not (rsDataset.EOF And rsDataset.BOF) Then
        With rsMain
            Do While Not rsDataset.EOF
                .AddNew
                .Fields("NOME") = rsDataset("U1.NOME")
                .Fields("COGNOME") = rsDataset("U1.COGNOME")
                .Fields("TIPO") = Choose(rsDataset(IIf(tEliminazione = tpUTENTI, "U1.", "") & "TIPO"), "Medico", "Infermiere", "Contabile", "Amministratore")
                .Fields("DATA") = rsDataset("DATA")
                .Fields("ORA") = Format(rsDataset("ORA"), "Short Time")
                .Fields("NOME_PAZIENTE") = rsDataset("P.NOME")
                .Fields("COGNOME_PAZIENTE") = rsDataset("P.COGNOME")
                .Fields("DATA_ESAME") = rsDataset("DATA_ESAME")
                .Fields("ORGANO") = GetNome(rsDataset("CODICE_ORGANO"), "ORGANI")
                .Fields("ESAME") = GetNome(rsDataset("CODICE_ESAME"), "ESAMI")
                rsDataset.MoveNext
            Loop
        End With
    End If
    rsDataset.Close
    Set rsDataset = Nothing
        
    Set rptEsamiStrumentaliEliminazione.DataSource = rsMain
    rptEsamiStrumentaliEliminazione.Orientation = rptOrientLandscape
    rptEsamiStrumentaliEliminazione.PrintReport True, rptRangeAllPages
End Sub

Private Function Completo() As Boolean
    Completo = False
        If flxGriglia.Rows <= 1 Then
            MsgBox "IMPOSSIBILE STAMPARE" & vbCrLf & "Dati mancanti", vbCritical, "Attenzione"
            Exit Function
        End If
    Completo = True
End Function

Public Sub MouseWheel(flx As MSFlexGrid, ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
    Dim NewValue As Long
    Dim Lstep As Single

    On Error Resume Next
    With flx
        Lstep = .Height / .RowHeight(0)
        Lstep = Int(Lstep)
        If Lstep < 10 Then
            Lstep = 10
        End If
        If Rotation > 0 Then
            NewValue = .TopRow - Int(Lstep / 3)
            If NewValue < 1 Then
                NewValue = 1
            End If
        Else
            NewValue = .TopRow + Int(Lstep / 3)
            If NewValue > .Rows - 1 Then
                NewValue = .Rows - 1
            End If
        End If
        .TopRow = NewValue
    End With
End Sub

Private Sub CaricaFlx()
    Dim rsDataset As Recordset
    Dim dataInizio As Date
    Dim dataFine As Date
    Dim strData As String
    Dim strUtente As String
    Dim strSql As String
    Dim riga As Integer
    Dim nomeTabella As String
    
    With tFiltro
        If .dataMin <> CDate("0.00.00") And .dataMax <> CDate("0.00.00") Then
            dataInizio = DateValue(Month(.dataMin) & "/" & Day(.dataMin) & "/" & Year(.dataMin))
            dataFine = DateValue(Month(.dataMax) & "/" & Day(.dataMax) & "/" & Year(.dataMax))
            strData = " AND DATA BETWEEN #" & dataInizio & "# AND #" & dataFine & "# "
        ElseIf (.dataMin <> CDate("0.00.00") And .dataMax = CDate("0.00.00")) Or (.dataMax <> CDate("0.00.00") And .dataMin = CDate("0.00.00")) Then
            Exit Sub
        End If
        If .indexUtente <> 0 Then
            strUtente = " AND CODICE_UTENTE=" & .indexUtente
        End If
        If .unSoloTipo Then
            strUtente = " AND U1.TIPO=" & .tipo
        End If
    End With
    riga = 0
    flxGriglia.Rows = 1
    
    Select Case tEliminazione
        Case tpLAB
            strSql = "SELECT * FROM ((LOGIN U1 INNER JOIN E_ESAMI_LAB E ON U1.KEY=E.CODICE_UTENTE)INNER JOIN PAZIENTI P ON P.KEY=E.CODICE_PAZIENTE) INNER JOIN INFO_ESAMI_LAB I ON E.KEY=I.CODICE_ELIMINAZIONE WHERE TRUE " & strData & strUtente
        Case tpSTRUMETALI, tpTERAPIEDIALITICHE, tpTERAPIEDOMICILIARI
            Select Case tEliminazione
                Case tpSTRUMETALI: nomeTabella = "E_ESAMI_STRUMENTALI"
                Case tpTERAPIEDIALITICHE: nomeTabella = "E_TERAPIE_DIALITICHE"
                Case tpTERAPIEDOMICILIARI: nomeTabella = "E_TERAPIE_DOMICILIARI"
            End Select
            strSql = "SELECT * FROM (LOGIN U1 INNER JOIN " & nomeTabella & " E ON U1.KEY=E.CODICE_UTENTE) INNER JOIN PAZIENTI P ON P.KEY=E.CODICE_PAZIENTE WHERE TRUE " & strData & strUtente
        Case tpUTENTI
            strSql = "SELECT * FROM (LOGIN U1 INNER JOIN E_UTENTI E ON U1.KEY=E.CODICE_UTENTE) INNER JOIN LOGIN U2 ON U2.KEY=E.CODICE_ELIMINATO WHERE TRUE " & strData & strUtente
    End Select
    
    strSql = strSql & " ORDER BY DATA DESC"
    
    Set rsDataset = New Recordset
    rsDataset.Open strSql, cnPrinc, adOpenForwardOnly, adLockReadOnly, adCmdText
    If Not (rsDataset.EOF And rsDataset.BOF) Then
        With flxGriglia
            Do While Not rsDataset.EOF
                riga = riga + 1
                .Rows = riga + 1
                .TextMatrix(riga, 0) = rsDataset("E.KEY")
                .TextMatrix(riga, 1) = rsDataset("U1.NOME")
                .TextMatrix(riga, 2) = rsDataset("U1.COGNOME")
                .TextMatrix(riga, 3) = Choose(rsDataset(IIf(tEliminazione = tpUTENTI, "U1.", "") & "TIPO"), "Medico", "Infermiere", "Contabile", "Amministratore")
                .TextMatrix(riga, 4) = rsDataset("DATA")
                .TextMatrix(riga, 5) = Format(rsDataset("ORA"), "Short Time")
                If tEliminazione = tpUTENTI Then
                    .TextMatrix(riga, 6) = rsDataset("U2.NOME")
                    .TextMatrix(riga, 7) = rsDataset("U2.COGNOME")
                Else
                    .TextMatrix(riga, 6) = rsDataset("P.NOME")
                    .TextMatrix(riga, 7) = rsDataset("P.COGNOME")
                End If
                Select Case tEliminazione
                    Case tpLAB
                        .TextMatrix(riga, 8) = rsDataset("DATA_ESAME")
                        .TextMatrix(riga, 9) = GetNome(rsDataset("CODICE_ESAME"), "GRUPPI_ESAMI")
                    Case tpSTRUMETALI
                        .TextMatrix(riga, 8) = rsDataset("DATA_ESAME")
                        .TextMatrix(riga, 9) = GetNome(rsDataset("CODICE_ORGANO"), "ORGANI")
                        .TextMatrix(riga, 10) = GetNome(rsDataset("CODICE_ESAME"), "ESAMI")
                    Case tpTERAPIEDIALITICHE
                        .TextMatrix(riga, 8) = rsDataset("DATA_TERAPIA")
                        .TextMatrix(riga, 9) = GetNome(rsDataset("CODICE_MEDICINALE"), "MEDICINALI")
                        .TextMatrix(riga, 10) = rsDataset("POSOLOGIA")
                        .TextMatrix(riga, 11) = IIf(rsDataset("SOMMINISTRAZIONE") = 1, "Intradialitica", "Postdialitica")
                        .TextMatrix(riga, 12) = rsDataset("NOTE")
                        .TextMatrix(riga, 13) = IIf(rsDataset("GIORNO1"), ICS, "")
                        .TextMatrix(riga, 14) = IIf(rsDataset("GIORNO2"), ICS, "")
                        .TextMatrix(riga, 15) = IIf(rsDataset("GIORNO3"), ICS, "")
                        .TextMatrix(riga, 16) = IIf(rsDataset("GIORNO4"), ICS, "")
                        .TextMatrix(riga, 17) = IIf(rsDataset("GIORNO5"), ICS, "")
                        .TextMatrix(riga, 18) = IIf(rsDataset("GIORNO6"), ICS, "")
                        .TextMatrix(riga, 19) = IIf(rsDataset("GIORNO7"), ICS, "")
                        .TextMatrix(riga, 20) = IIf(rsDataset("TUTTI_GIORNI"), ICS, "")
                        .TextMatrix(riga, 21) = IIf(rsDataset("SOSPESA"), ICS, "")
                        .TextMatrix(riga, 22) = rsDataset("DATA_SOSPESA") & ""
                        .TextMatrix(riga, 23) = IIf(rsDataset("CONFERMA_SOMMINISTRAZIONE"), ICS, "")
                    Case tpTERAPIEDOMICILIARI
                        .TextMatrix(riga, 8) = rsDataset("DATA_TERAPIA")
                        .TextMatrix(riga, 9) = GetNome(rsDataset("CODICE_MEDICINALE"), "MEDICINALI")
                        .TextMatrix(riga, 10) = rsDataset("POSOLOGIA")
                        .TextMatrix(riga, 11) = rsDataset("SOMMINISTRAZIONE")
                        .TextMatrix(riga, 12) = IIf(rsDataset("GIORNO1"), ICS, "")
                        .TextMatrix(riga, 13) = IIf(rsDataset("GIORNO2"), ICS, "")
                        .TextMatrix(riga, 14) = IIf(rsDataset("GIORNO3"), ICS, "")
                        .TextMatrix(riga, 15) = IIf(rsDataset("GIORNO4"), ICS, "")
                        .TextMatrix(riga, 16) = IIf(rsDataset("GIORNO5"), ICS, "")
                        .TextMatrix(riga, 17) = IIf(rsDataset("GIORNO6"), ICS, "")
                        .TextMatrix(riga, 18) = IIf(rsDataset("GIORNO7"), ICS, "")
                        .TextMatrix(riga, 19) = IIf(rsDataset("TUTTI_GIORNI"), ICS, "")
                        .TextMatrix(riga, 20) = IIf(rsDataset("SOSPESA"), ICS, "")
                        .TextMatrix(riga, 21) = rsDataset("DATA_SOSPESA") & ""
                    Case tpUTENTI
                        .TextMatrix(riga, 8) = Choose(rsDataset("U2.TIPO"), "Medico", "Infermiere", "Contabile", "Amministratore")
                End Select
                rsDataset.MoveNext
            Loop
        End With
    Else
        'MsgBox "Nessun elemento trovato", vbInformation, "Isodial Utility"
    End If
    Set rsDataset = Nothing
End Sub

Private Sub cmdChiudi_Click()
    Unload Me
End Sub

Private Sub cmdStampa_Click()
    If Completo Then
        frmFiltroStampa.Show 1
        Select Case tEliminazione
            Case tpSTRUMETALI:           Call StampaEsamiStrumentaliEliminazione     'rptEsamiStrumentaliEliminazione
            Case tpLAB:                  Call StampaEsamiLabEliminazione             'rptEsamiLabEliminazione
            Case tpUTENTI:               Call StampeUtentiEliminazione               'rptUtentiEliminazione
            Case tpTERAPIEDIALITICHE:    Call StampaTerapieDialitiche                'rptTerapieDialiticheEliminazione
            Case tpTERAPIEDOMICILIARI:   Call StampaTerapieDomiciliari               'rptTerapieDomiciliariEliminazione
        End Select
    End If
End Sub

Private Sub flxGriglia_GotFocus()
    Call WheelHook(Me, flxGriglia)
End Sub

Private Sub flxGriglia_LostFocus()
    Call WheelUnHook
End Sub

Private Sub flxGriglia_Click()
    If Not VerificaClickFlx(flxGriglia) Then
        ' discolora
        Call ColoraFlx(flxGriglia, flxGriglia.Cols - 1, vbWhite)
        ' annulla le row e col
        flxGriglia.Row = 0
        flxGriglia.Col = 0
    Else
        Call ColoraFlx(flxGriglia, flxGriglia.Cols - 1)
    End If
End Sub

Private Sub flxGriglia_DblClick()
    Dim i As Integer
    If Not VerificaClickFlx(flxGriglia) Then Exit Sub
    With flxGriglia
        ReDim v_nomi(.Cols - 1)
        ReDim v_val(.Cols - 1)
        For i = 1 To .Cols - 1
            v_nomi(i) = .TextMatrix(0, i)
            v_val(i) = .TextMatrix(.Row, i)
        Next i
    End With
    tVisualizza = tpELIMINAZIONI
    frmVisualizza.Show 1
End Sub

Private Sub lblFiltro_Change()
    With frmMain
        tFiltro.indexUtente = IIf(.flxUtenti.Row = 0, 0, .flxUtenti.TextMatrix(.flxUtenti.Row, 0))
        tFiltro.dataMin = IIf(.lblData(0) = "", 0, .lblData(0))
        tFiltro.dataMax = IIf(.lblData(1) = "", 0, .lblData(1))
        tFiltro.unSoloTipo = (.chkUnSoloTipo.Value = Checked)
        tFiltro.tipo = .cboTipo.ListIndex + 1
    End With
    Call CaricaFlx
End Sub

